package com.example.expedition.data.modules.sys.service;

import com.example.expedition.data.common.utils.UUIDUtils;
import com.example.expedition.data.modules.sys.dao.UserMapper;
import com.example.expedition.data.modules.sys.entity.User;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * 描述：
 *
 * @author zengyz
 * @date 2018/8/22 10:53
 */
@Service
@Transactional(rollbackFor = {Exception.class, RuntimeException.class})
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public int add(User user) throws Exception{
        user.setId(UUIDUtils.getUUID32());
        user.setPassword(DigestUtils.md5Hex(user.getPassword()));
        user.setCreateTime(new Date());
        return userMapper.insert(user);
    }
}
